//
//  NSObject+Ext.swift
//  WBSwift
//
//  Created by 贺瑞 on 2017/8/8.
//  Copyright © 2017年 herui. All rights reserved.
//

import UIKit

extension NSObject {
    
    static func objFormClassString(str : String?) -> BaseModel? {
        guard let str =  str else {
            return nil
        }

        let namespace = Bundle.main.infoDictionary?["CFBundleExecutable"] as! String
        
        guard let cls =  NSClassFromString("\(namespace).\(str)") else {
            return nil
        }
        return objFormClass(cls: cls)
    }
    
    static func objFormClass(cls : AnyClass?) -> BaseModel? {
        guard let clsType = cls as? BaseModel.Type else {
            return nil
        }
        return clsType.init()
    }

}
